﻿using System.Collections.Generic;
using System.Linq;
using ConsolePresentation;

namespace BasicAdoNet
{
    public class TerritoriesService : ITerritoriesService
    {
        private readonly ITerritoriesRepository _repository;

        public TerritoriesService(ITerritoriesRepository repository)
        {
            _repository = repository;
        }

        public IEnumerable<ConsolePresentation.Territory> GetTerritoriesByRegionId(int id)
        {
            return _repository.GetTerritoriesByRegionId(id).Select(
                item =>
                new ConsolePresentation.Territory
                    {
                        Description = item.Description,
                        Id = item.Id,
                        Region = new ConsolePresentation.Region
                            {
                                Id = item.Region.Id,
                                Description = item.Description
                            }
                    });
        }

        public IEnumerable<ConsolePresentation.Territory> GetTerritoriesFilterByDescription(string description)
        {
            return _repository.GetTerritoriesFilterByDescription(description).Select(
                item =>
                new ConsolePresentation.Territory
                    {
                        Description = item.Description,
                        Id = item.Id,
                        Region = new ConsolePresentation.Region
                            {
                                Id = item.Region.Id,
                                Description = item.Description
                            }
                    });
        }

        public IEnumerable<ConsolePresentation.Region> GetAllRegions()
        {
            return _repository.GetAllRegions().Select(
                item =>
                new ConsolePresentation.Region
                    {
                        Id = item.Id,
                        Description = item.Description
                    });
        }
    }
}